[center][size=4]Loading MANY Images[/size][/center]

[center][size=3]by Welopez[/size][/center]



Let's suppose you are adding an animated image to a graphic display.  You will probably have "sillyMan-1.bmp", "sillyMan-2.bmp", and perhaps 3 to 23 images to be loaded and unloaded for your program.  I recently encountered this when writing a routine for playing cards.

By using a numeric value in [i]filename-[b]k[/b].bmp"[/i], you can use a simple loop to load and unload ALL images and not have to type umpteen lines of code.
[code]
FOR k=1 to n  'where n is the total number of images
	LOADBMP "name";k, "sillyMan-";k;".bmp"  "name" is the working name
NEXT k
[/code]
At the end of the program, you can similarly UNLOADBMP.  When unloading, it is not necessary to specify the .bmp filename, only the working name.

The following code loads 53 images for a deck of cards.  card-0.bmp is the back of all playing cards; card-1 through card-52.bmp is the front of the individual cards.[code]
'Loading MANY image files by Welo, 102206

FOR k=0 TO 52
    LOADBMP "card";k, "card-";k;".bmp"
NEXT k

WindowWidth=600
WindowHeight=400
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)

BUTTON #g.btn1, "CLOSE", [quit], LL, 270, 15, 60, 30

OPEN "Show Playing Cards" FOR GRAPHICS_nsb AS #g
PRINT #g, "trapclose [quit]"
PRINT #g, "DOWN"
PRINT #g, "FILL 0 212 0"

x=25  'the initial x and y coordinates to print the images
y=25
WHILE z<52
    z=z+1  'counter for the image to be drawn
    PRINT #g, "DRAWBMP card"; z ; " " ; x ; " "; y
    x=x+40
    IF z MOD 13=0 THEN  'if 13 cards have been dealt
        x=25    'begin at the left again
        y=y+50  'drop down to the next row
    END IF
WEND

PRINT #g, "DRAWBMP card0 25 "; y  'prints the image for back of cards

FOR k=1 TO 5  'let's print 5 random cards
    x=x+25
    PRINT #g, "DRAWBMP card";INT(RND(0)*52)+1; " "; x; " "; y
NEXT k
PRINT #g, "FLUSH"

WAIT
[quit]
FOR k=0 TO 52  'unload all the images
    UNLOADBMP "card";k
NEXT k
    CLOSE #g
    END
    NOMAINWIN  'The NOMAINWIN statement can go anywhere in your program
[/code]
The first thing we do is load all the images, even before defining the GUI.  After all the images are loaded, we use a WHILE/WEND to print images 1 through 52.  Each image is printed 40 pixels to the right of the previous image.  IF z MOD 13=0 means we have dealt 13 cards, so we drop down to the next row to print the next suit.

After all four suits have been printed, we print the image of the card back, and then deal 5 cards at random, much as if you were dealing a poker hand.

I put the NOMAINWIN at the end of the program, merely to show it can be placed anywhere in your code.

Of course, you cannot run this code without the images of playing cards for LOADBMP and UNLOADBMP.  You can download a ZIP containing the code and 53 BMP images for the cards from the Demos section of the Just B asic Files Archive, [url=http://jbusers.com/phpBB/viewforum.php?f=10] Loading MANY Images.[/url]  Hey, you never can tell when you'll need all the images for a deck of cards!
